#include "geom.h"
#include "TexturedEntity.h"
#include "LinearTrajectory.h"

LinearTrajectory::LinearTrajectory(TexturedEntity* entity, const float Vx, const float factor, 
                                   const float horizFactor, const float vertFactor)
: Behaviour(entity), m_Vx(Vx), m_factor(factor), m_horizFactor(horizFactor), m_vertFactor(vertFactor)
{
}

LinearTrajectory::~LinearTrajectory(void)
{
}

void LinearTrajectory::prepare(float dt)
{
    // Calculate new position
    Vector3 newPosition = m_entity->getPosition();
    newPosition.x += m_Vx * m_horizFactor * m_factor * dt;
    newPosition.y -= m_vertFactor * GRAVITY * m_factor * dt;

    // Check if new position is out of screen bounds
    if (m_entity->isOutOfScreen())
    {
        m_entity->destroy();
    }

    // Set the entity's position
    m_entity->setPosition(newPosition);
}
